//查询
function searchList() {
    $.ajax({
        url:root.serviceProviderManagement.listServiceOrder,
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        contentType: "application/json",
        data: JSON.stringify({
            pageNum: 1, //当前页码
            pageSize: 50,//每页显示条数
            "parentCustomerCode":$("#ascription_lsit").val(),
            "providerName":$("#providerName").val(),
            "productCode":$("#productCode").val(),
            "orderId": $("#orderId").val(),
            "channelOrderId":$("#channelOrderId").val(),
            "orderStatus":$("#orderStatus").val(),
            "createdOrderBegin":$("#createdOrderBegin").val(),
            "createdOrderEnd":$("#createdOrderEnd").val(),
            "pushOrderBegin":$("#pushOrderBegin").val(),
            "pushOrderEnd":$("#pushOrderEnd").val(),
            "receiverName":$("#receiverName").val(),
            "receiverPhone":$("#receiverPhone").val(),
            "receiverProvince":$("#getArea").val(),
            "receiverCity":$("#getPlace").val(),
            "sentType":$("#sent_type").val(),
            "finalTotalAmountLow":$("#paid_amount_min").val(),
            "finalTotalAmountHigh":$("#paid_amount_max").val(),
            "uploadProofStatus":$("#uploadProofStatus").val(),

        }),
        success: function (data) {
            initDataTable(data.data);
            $('.M-box3').pagination({
                pageCount: data.data.pageCount,
                jump: true,
                coping: true,
                prevContent: '上页',
                nextContent: '下页',
                callback: function (api) {
                    $.ajax({
                        url: root.serviceProviderManagement.listServiceOrder,
                        cache: false,  //禁用缓存
                        type: "POST",
                        dataType:'json',
                        contentType: "application/json",
                        data: JSON.stringify({
                            "pageNum":api.getCurrent(),
                            "pageSize":50,
                            "parentCustomerCode":$("#ascription_lsit").val(),
                            "providerName":$("#providerName").val(),
                            "productCode":$("#productCode").val(),
                            "orderId": $("#orderId").val(),
                            "channelOrderId":$("#channelOrderId").val(),
                            "orderStatus":$("#orderStatus").val(),
                            "createdOrderBegin":$("#createdOrderBegin").val(),
                            "createdOrderEnd":$("#createdOrderEnd").val(),
                            "pushOrderBegin":$("#pushOrderBegin").val(),
                            "pushOrderEnd":$("#pushOrderEnd").val(),
                            "receiverName":$("#receiverName").val(),
                            "receiverPhone":$("#receiverPhone").val(),
                            "receiverProvince":$("#getArea").val(),
                            "receiverCity":$("#getPlace").val(),
                            "sentType":$("#sent_type").val(),
                            "finalTotalAmountLow":$("#paid_amount_min").val(),
                            "finalTotalAmountHigh":$("#paid_amount_max").val(),
                            "uploadProofStatus":$("#uploadProofStatus").val(),

                        }),
                        success: function (result) {
                            initDataTable(result.data);
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            alert(XMLHttpRequest);
                        }
                    });
                }
            });

        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });
}
var dataSource = new Array();
var table;   //table对象
dataSource = [];
var orderstatusall={
    '10':"待确认","20":"待审核",'30':"待配货",'40':"待出库",'50':"待发货",'60':"待收货",'70':"已收货待结算",'80':"订单成功",'90':"交易完成",'100':"订单取消",'110':"交易关闭"
}
function couponlist(data, index){
    sessionStorage.setItem("authorizedUsers", JSON.stringify(data));
    dataSource.splice(0,dataSource.length);//清空数组
    if(data.data !=null && data.data != ''){
        $.each(data.data, function (i, field) {
            var rowData = new Array();
            rowData.push(field.orderId);
            rowData.push(field.parentCustomerName);
            rowData.push(field.providerName);
            rowData.push(field.createdOrderAt);
            rowData.push(field.finalTotalAmount);
            rowData.push(field.orderStatus);
            rowData.push(field.id);
            rowData.push(field.rateTotalAmount);
            dataSource.push(rowData);

        });

    }
    initDataTable(dataSource);
    
}

function initDataTable(dataSource) {

    var dttable = $('#datatable').dataTable(); // 初始化dataTable，清空上一个值
    dttable.fnClearTable(); //清空一下table
    dttable.fnDestroy(); //还原初始化了的datatable
    $("#datatable").DataTable({
        // "order": false,
        "autoWidth": false,
        "ordering": false,
        "searching": false,
        "paging": false,
        "retrieve": true,
        "destroy": true,
        "bAutoWidth": true,
        "bLengthChange": true,
        "aLengthMenu": false,
        "oLanguage": {
            "sLengthMenu": "每页显示 _MENU_ 条记录",
            "sZeroRecords": "抱歉， 没有找到",
            "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
            "sInfoEmpty": "没有数据",
            "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "前一页",
                "sNext": "后一页",
                "sLast": "尾页"
            },
            "sZeroRecords": "没有检索到数据",
        },
        data: dataSource.data,
        columnDefs: [
            {
                "visible": true,
                "targets": 0
            },
            {
                "render": function (data, type, row, meta) {
                    var val = row.orderId
                    if (val == undefined) {
                        val = ''
                    }
                    return val;
                },
                "targets": 0
            },

            {
                "render": function (data, type, row, meta) {
                    var val = row.parentCustomerName
                    if (val == undefined) {
                        val = ''
                    }
                    return val;
                },
                "targets": 1
            },
            {
                "render": function (data, type, row, meta) {
                    var val = row.providerName
                    if (val == undefined) {
                        val = ''
                    }
                    return val;
                },
                "targets":2
            },
            {
                "render": function (data, type, row, meta) {
                    var val = row.createdOrderAt
                    if (val == undefined) {
                        val = ''
                    }
                    return val;
                },
                "targets":3
            },
            {
                "render": function (data, type, row, meta) {
                    var val = row.createdAt
                    if (val == undefined) {
                        val = ''
                    }
                    return val;
                },
                "targets":4
            },
            {
                "render": function (data, type, row, meta) {
                    var val = row.finalTotalAmount
                    if (val == undefined) {
                        val = ''
                    }
                    return val;
                },
                "targets": 5
            },
            {
                "render": function (data, type, row, meta) {
                    var val = row.rateTotalAmount
                    if (val == undefined) {
                        val = ''
                    }
                    return val;
                },
                "targets": 6
            },
            {
                "render": function (data, type, row, meta) {
                    var val = orderstatusall[row.orderStatus]
                    if (val == undefined) {
                        val = ''
                    }
                    return val;
                },
                "targets": 7
            },
            {
                "render": function (data, type, row, meta) {
                    var val='<span class="ml-10"><a onclick="jumpData(\'详情\',\'orderDetails.html\',\''+row.orderId+'\',\''+row.id+'\')">查看详情</a></span>'
                    return val;
                },
                "targets": 8
            }


        ]
    });
    //权限控制函数
    power()
};

/*获取收货地址*/
discountdata(123)
function discountdata (val) {
    if(val==123){
        //初始化 省
        var user_data = {
            level: '101',
            // memberId:'10258',
        }
        var succCallBack = function (data, status, response) {
            if(data.errorCode=="0"){
                var tab_data=data.list;
                if(tab_data==''){
                    cer+='<option value=""></option>'
                    $("#getArea").html(cer);
                }else{
                    var cer="<option value=''>请选择收货区域</option>"
                    for(var i=0; i<tab_data.length; i++){
                        cer+='<option value="'+tab_data[i].code+'">'+tab_data[i].name+'</option>'
                    }
                    $("#getArea").html(cer);
                }
            }
        };
        web.doAjax(root.member.getLowerAddress,'post',user_data, succCallBack);
    }else if(val==1){
        //市
        var special=$('#getArea').val()
        if(special==""){
            var cer="<option value=''>请选择收货位置</option>"
            $("#getPlace").html(cer);
        }else {
            var user_data = {
                level: '102',
                // memberId:'10258',
                parentCode:special
            }
            var succCallBack = function (data, status, response) {
                if(data.errorCode=="0"){
                    var tab_data=data.list;
                    if(tab_data==''){
                        cer+='<option value=""></option>'
                        $("#getPlace").html(cer);
                    }else{
                        var cer="<option value=''>请选择收货位置</option>"
                        for(var i=0; i<tab_data.length; i++){
                            cer+='<option value="'+tab_data[i].code+'">'+tab_data[i].name+'</option>'
                        }
                        $("#getPlace").html(cer);
                    }
                }
            };
            web.doAjax(root.member.getLowerAddress,'post',user_data, succCallBack);
        }
    }
}
//金额输入
function functionMax() {
    if ($("#paid_amount_min").val() != null && $("#paid_amount_max").val() != null) {
        if (parseFloat($("#paid_amount_max").val()) <= parseFloat($("#paid_amount_min").val())) {
            var s = "输入金额应大于第1个输入框";
            $.Huimodalalert(s, 1000);
        }
    }
}

//跳转
function jumpData(title,url,id,orderBaseId) {
    sessionStorage.setItem("serviceProviderorderid",id)
    sessionStorage.setItem("orderBaseIds",orderBaseId)
    var index = layer.open({
        type: 2,
        title: title,
        content: url
    });
    layer.full(index);
}

ascription2()
function ascription2() {
    $.ajax({
        type: "post",
        url:root.dockingplatform.allChannelConfig,
        cache: false,  //禁用缓存
        dataType: "json",
        data: {

        },
        success: function (data) {
            if(data.errorCode=="0") {
                var dataInter=data.data;
                var interText = doT.template($("#ascription_bob").text());
                $("#ascription_lsit").html(interText(dataInter));
            }

        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });
}
//导出订单
function exportOrder() {
    //时间
    var createdOrderBegin=""
    if($("#createdOrderBegin").val()==""){
        createdOrderBegin=""
    }else {
        createdOrderBegin='&createdOrderBegin='+''+$("#createdOrderBegin").val()
    }
    var createdOrderEnd=""
    if($("#createdOrderEnd").val()==""){
        createdOrderEnd=""
    }else {
        createdOrderEnd='&createdOrderEnd='+''+$("#createdOrderEnd").val()
    }
    var pushOrderBegin=""
    if($("#pushOrderBegin").val()==""){
        pushOrderBegin=''
    }else {
        pushOrderBegin='&pushOrderBegin='+''+$("#pushOrderBegin").val()
    }
    var pushOrderEnd=""
    if($("#pushOrderEnd").val()==""){
        pushOrderEnd=""
    }else {
        pushOrderEnd='&pushOrderEnd='+''+$("#pushOrderEnd").val()
    }
        //导出
        $('#exportOrder').attr('href',root.serviceProviderManagement.exportOrderList+'?'
            +'parentCustomerCode='+''+$("#ascription_lsit").val()+''+'&providerName='+''+$("#providerName").val()+''+'&productCode='+''+$("#productCode").val()
            +''+'&orderId='+''+$("#orderId").val()+'&channelOrderId='+''+$("#channelOrderId").val()+'&orderStatus='+''+$("#orderStatus").val()
            +createdOrderBegin+createdOrderEnd+pushOrderBegin+pushOrderEnd
            +'&receiverName='+''+$("#receiverName").val()+'&receiverPhone='+''+$("#receiverPhone").val()
            +'&receiverProvince='+''+$("#getArea").val()+'&receiverCity='+''+$("#getPlace").val()+'&sentType='+''+$("#sent_type").val()
            +'&finalTotalAmountLow='+''+$("#paid_amount_min").val()+'&finalTotalAmountHigh='+''+$("#paid_amount_max").val()+'&uploadProofStatus='+''+$("#uploadProofStatus").val());
}